
<template>
    <div v-loading.fullscreen.lock="fullscreenLoading" :element-loading-text="nowLangue.loadDesperately">
        <el-form :inline="true" :model="formInline" class="demo-form-inline" style="border-bottom:1px solid #ccc;">
            <!--计划大类-->
            <el-form-item :label="nowLangue.planClass" class="selectMB10">
                <el-select size="mini" clearable v-model="formInline.status" :placeholder="nowLangue.pleaseSelect">
                    <el-option v-for="(status,index) in statusList" :key="index" :label="status.label" :value="status.value"></el-option>
                </el-select>
            </el-form-item>
            <!--备件小类-->
            <el-form-item :label="nowLangue.spareClass" class="selectMB10">
                <el-select size="mini" clearable v-model="formInline.status" :placeholder="nowLangue.pleaseSelect">
                    <el-option v-for="(status,index) in statusList" :key="index" :label="status.label" :value="status.value"></el-option>
                </el-select>
            </el-form-item>
            <!--创建时间-->
            <div class="dayChose">
                <el-form-item :label="nowLangue.createTime" class="selectMB10" >
                    <el-date-picker type="date" :editable="false" v-model="formInline.startCreateTime" clearable :placeholder="nowLangue.pleaseSelect" @change="selectedCreateTimeBegin"></el-date-picker>
                </el-form-item>
                <span v-text="nowLangue.to"></span>
                <el-form-item  class="selectMB10" >
                    <el-date-picker clearable :editable="false" v-model="formInline.endCreateTime"  type="date" :placeholder="nowLangue.pleaseSelect" @change="selectedCreateTimeEnd"></el-date-picker>
                </el-form-item>
            </div>
            <el-form-item class="selectMB10">
                <el-button class="bolder outsideBtnBS selectAll" :disabled="selectDisabled" size="mini" type="danger" @click="queryClick()" v-text="nowLangue.query"></el-button>
            </el-form-item>
        </el-form>
        <!--表格-->
        <label class="default-label" v-text="nowLangue.shortFailureDetail"></label>
        <el-button class="bolder outsideBtnBS" :disabled="addDisabled" size="mini" type="danger" @click="add" v-text="nowLangue.create"></el-button>
        <el-button class="bolder outsideBtnBS" :disabled="leadInDisabled" size="mini" type="danger" @click="importFile" v-text="nowLangue.leadIn"></el-button>
        <el-button class="bolder outsideBtnBS" :disabled="leadOutDisabled" size="mini" type="danger" @click="leadingOutMask" v-text="nowLangue.leadOut"></el-button>
        <el-table :data="shortFailureData" border style="width: 100%;" v-loading.body="loading" :element-loading-text="nowLangue.loadDesperately">
            <el-table-column type="index" header-align="center" align="center" :label="nowLangue.sequence" width="40"></el-table-column>
            <!--操作-->
            <el-table-column :label="nowLangue.operate" header-align="center" align="center" width="80">
                <template scope="scope">
                    <button class="operationItem bolder" :disabled="forbiddenDisabled" v-if="scope.row.status" @click="handleStatus(scope.$index,scope.row)" v-text="nowLangue.forbidden"></button>
                    <button class="operationItem bolder" :disabled="enableDisabled" v-else @click="handleStatus(scope.$index,scope.row)" v-text="nowLangue.enable"></button>
                    <button class="operationItem bolder" :disabled="scope.row.status" @click="update(scope.$index,scope.row)" v-text="nowLangue.update"></button>
                </template>
            </el-table-column>
            <!--计划大类-->
            <el-table-column prop="" :label="nowLangue.planClass" header-align="center"  show-overflow-tooltip></el-table-column>
            <!--备件小类-->
            <el-table-column prop="" :label="nowLangue.spareClass" header-align="center"  show-overflow-tooltip></el-table-column>
            <!--天数-->
            <el-table-column prop="" :label="nowLangue.days" header-align="center"  show-overflow-tooltip></el-table-column>
            <!--类型-->
            <el-table-column prop="" :label="nowLangue.type" header-align="center"  show-overflow-tooltip></el-table-column>
            <!--标签颜色-->
            <el-table-column prop="" :label="nowLangue.labelColor" header-align="center"  show-overflow-tooltip></el-table-column>
            <!--说明-->
            <el-table-column prop="" :label="nowLangue.describe" header-align="center"  show-overflow-tooltip></el-table-column>
            <!--话术-->
            <el-table-column prop="" :label="nowLangue.theWords" header-align="center"  show-overflow-tooltip></el-table-column>
            <!--创建人-->
            <el-table-column prop="" :label="nowLangue.creator" header-align="center"  show-overflow-tooltip></el-table-column>
            <!--创建时间-->
            <el-table-column prop="" :label="nowLangue.createTime" header-align="center"  show-overflow-tooltip></el-table-column>
            <!--修改人-->
            <el-table-column prop="" :label="nowLangue.updater" header-align="center"  show-overflow-tooltip></el-table-column>
            <!--修改时间-->
            <el-table-column prop="" :label="nowLangue.updateTime" header-align="center"  show-overflow-tooltip></el-table-column>
        </el-table>
        <el-pagination v-if="isPaging"  @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page.sync="currentPage3" :current-page="pageIndex"  :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :page-count="totalPage" :total="totalNumber"></el-pagination>
        <!--新增弹窗-->
        <el-dialog :title="nowLangue.addShortFailureDetail" :visible.sync="dialogAddVisible" size="tiny" :lock-scroll=false>
            <el-form :inline="true" :model="addShortFailureForm" class="demo-form-inline label-minW95" style="border-bottom:1px solid #ccc;" ref="addShortFailureForm">
                <!--计划大类-->
                <el-form-item :label="nowLangue.planClass" prop="code" :rules="[{ required: true, message: nowLangue.pleaseImport}]">
                    <el-select size="mini" :placeholder="nowLangue.pleaseImport" v-model="addShortFailureForm.subClassCode">
                        <el-option></el-option>
                    </el-select>
                </el-form-item>
                <!--备件小类-->
                <el-form-item :label="nowLangue.spareClass" prop="code" :rules="[{ required: true, message: nowLangue.pleaseImport}]">
                    <el-select size="mini" :placeholder="nowLangue.pleaseImport" v-model="addShortFailureForm.subClassCode">
                        <el-option></el-option>
                    </el-select>
                </el-form-item>
                <!--天数-->
                <el-form-item :label="nowLangue.days" prop="subClassCode" :rules="[{ required: true, message: nowLangue.pleaseImport}]">
                    <el-input v-model="addShortFailureForm.code" :placeholder="nowLangue.pleaseImport"></el-input>
                </el-form-item>
                <!--类型-->
                <el-form-item :label="nowLangue.type" prop="code" :rules="[{ required: true, message: nowLangue.pleaseImport}]">
                    <el-select size="mini" :placeholder="nowLangue.pleaseImport" v-model="addShortFailureForm.subClassCode">
                        <el-option></el-option>
                    </el-select>
                </el-form-item>
                <!--标签颜色-->
                <el-form-item :label="nowLangue.labelColor" prop="code" :rules="[{ required: true, message: nowLangue.pleaseImport}]">
                    <el-select size="mini" :placeholder="nowLangue.pleaseImport" v-model="addShortFailureForm.subClassCode">
                        <el-option></el-option>
                    </el-select>
                </el-form-item>
                <!--说明-->
                <el-form-item :label="nowLangue.describe" prop="code" :rules="[{ required: true, message: nowLangue.pleaseImport}]">
                    <el-input v-model="addShortFailureForm.code" type="textarea" resize="none" :placeholder="nowLangue.pleaseImport"></el-input>
                </el-form-item>
                <!--话术-->
                <el-form-item :label="nowLangue.theWords" prop="code" :rules="[{ required: true, message: nowLangue.pleaseImport}]">
                    <el-input v-model="addShortFailureForm.code" type="textarea" resize="none" :placeholder="nowLangue.pleaseImport"></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button class="bolder outsideBtnBS" size="mini" type="danger" v-text="nowLangue.sure"></el-button>
                <el-button class="bolder outsideBtnBS" size="mini" type="danger" v-text="nowLangue.cancel"></el-button>
            </div>
        </el-dialog>
        <!--修改弹窗-->
        <el-dialog :title="nowLangue.updateShortFailureDetail" :visible.sync="dialogUpdateVisible" size="tiny" :lock-scroll=false>
            <el-form :inline="true" :model="updateShortFailureForm" class="demo-form-inline label-minW95" style="border-bottom:1px solid #ccc;" ref="updateShortFailureForm">
                <!--计划大类-->
                <el-form-item :label="nowLangue.planClass" prop="code" :rules="[{ required: true, message: nowLangue.pleaseImport}]">
                    <el-select size="mini" :placeholder="nowLangue.pleaseImport" v-model="updateShortFailureForm.subClassCode">
                        <el-option></el-option>
                    </el-select>
                </el-form-item>
                <!--备件小类-->
                <el-form-item :label="nowLangue.spareClass" prop="code" :rules="[{ required: true, message: nowLangue.pleaseImport}]">
                    <el-select size="mini" :placeholder="nowLangue.pleaseImport" v-model="updateShortFailureForm.subClassCode">
                        <el-option></el-option>
                    </el-select>
                </el-form-item>
                <!--天数-->
                <el-form-item :label="nowLangue.days" prop="subClassCode" :rules="[{ required: true, message: nowLangue.pleaseImport}]">
                    <el-input v-model="updateShortFailureForm.code" :placeholder="nowLangue.pleaseImport"></el-input>
                </el-form-item>
                <!--类型-->
                <el-form-item :label="nowLangue.type" prop="code" :rules="[{ required: true, message: nowLangue.pleaseImport}]">
                    <el-select size="mini" :placeholder="nowLangue.pleaseImport" v-model="updateShortFailureForm.subClassCode">
                        <el-option></el-option>
                    </el-select>
                </el-form-item>
                <!--标签颜色-->
                <el-form-item :label="nowLangue.labelColor" prop="code" :rules="[{ required: true, message: nowLangue.pleaseImport}]">
                    <el-select size="mini" :placeholder="nowLangue.pleaseImport" v-model="updateShortFailureForm.subClassCode">
                        <el-option></el-option>
                    </el-select>
                </el-form-item>
                <!--说明-->
                <el-form-item :label="nowLangue.describe" prop="code" :rules="[{ required: true, message: nowLangue.pleaseImport}]">
                    <el-input v-model="updateShortFailureForm.code" type="textarea" resize="none" :placeholder="nowLangue.pleaseImport"></el-input>
                </el-form-item>
                <!--话术-->
                <el-form-item :label="nowLangue.theWords" prop="code" :rules="[{ required: true, message: nowLangue.pleaseImport}]">
                    <el-input v-model="updateShortFailureForm.code" type="textarea" resize="none" :placeholder="nowLangue.pleaseImport"></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button class="bolder outsideBtnBS" size="mini" type="danger" v-text="nowLangue.sure"></el-button>
                <el-button class="bolder outsideBtnBS" size="mini" type="danger" v-text="nowLangue.cancel"></el-button>
            </div>
        </el-dialog>
        <!--导入-->
        <el-dialog :title="nowLangue.leadShortFailureDetail" id="importFile" :visible.sync="importFileVisible" size="tiny"  :lock-scroll="false">
            <el-upload class="upload-demo"  :action="action" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel" :on-preview="handlePreview" :on-remove="handleRemove" :file-list="fileList" :before-upload="beforeAvatarUpload" :on-success="handleAvatarSuccess">
                <!--点击上传 -->
                <el-button size="mini" type="danger" v-text="nowLangue.clickUpload"></el-button>
                <!-- 只能上传excel文件-->
                <div slot="tip" class="el-upload__tip" v-text="nowLangue.uploadTip"></div>
            </el-upload>
        </el-dialog>
    </div>
</template>
<script>
    export default {
        data() {
            return {
                nowLangue:{},
                languageScoped:{
                    zh:{
                        "pleaseSelect":"请选择",
                        "pleaseImport":"请输入",
                        "query":"查询",
                        "loadDesperately":"拼命加载中",
                        "sequence":"序",
                        "operate":"操作",
                        "update":"修改",
                        "shortFailureDetail":"短期失效标准明细",
                        "addShortFailureDetail":"新增短期失效标准",
                        "updateShortFailureDetail":"修改短期失效标准",
                        "leadShortFailureDetail":"导入短期失效标准",
                        "forbidden":"禁用",
                        "enable":"启用",
                        "sure":"确定",
                        "cancel":"取消",
                        "create":"新增",
                        "leadIn":"导入",
                        "leadOut":"导出",
                        "clickUpload":"点击上传",
                        "uploadTip":"只能上传excel文件",
                        "planClass":"计划大类",
                        "spareClass":"备件小类",
                        "createTime":"创建时间",
                        "to":"至",
                        "creator":"创建人",
                        "updater":"修改人",
                        "updateTime":"最近修改时间",
                        "describe":"说明",
                        "days":"天数",
                        "type":"类型",
                        "labelColor":"标签颜色",
                        "theWords":"话术"
                    },
                    en:{
                        "pleaseSelect":"pleaseSelect",
                        "pleaseImport":"pleaseImport",
                        "query":"query",
                        "loadDesperately":"loadDesperately",
                        "sequence":"sequence",
                        "operate":"operate",
                        "update":"update",
                        "shortFailureDetail":"shortFailureDetail",
                        "addShortFailureDetail":"addShortFailureDetail",
                        "updateShortFailureDetail":"updateShortFailureDetail",
                        "leadShortFailureDetail":"leadShortFailureDetail",
                        "forbidden":"forbidden",
                        "enable":"enable",
                        "sure":"sure",
                        "cancel":"cancel",
                        "create":"create",
                        "leadIn":"leadIn",
                        "leadOut":"leadOut",
                        "clickUpload":"clickUpload",
                        "uploadTip":"uploadTip",
                        "createTime":"createTime",
                        "to":"to",
                        "spareClass":"spareClass",
                        "planClass":"planClass",
                        "creator":"creator",
                        "updater":"updater",
                        "updateTime":"updateTime",
                        "describe":"describe",
                        "days":"days",
                        "type":"type",
                        "labelColor":"labelColor",
                        "theWords":"theWords"
                    }
                },
                // 查询表单
                formInline:{

                },
                shortFailureData:[{
                    name:"aaa"
                }],
                /*新增*/
                dialogAddVisible:false,//新建弹窗
                addShortFailureForm:{},//新建查询表单

                /*修改*/
                dialogUpdateVisible:false,//修改弹窗
                updateShortFailureForm:{},//新建查询表单

                /*导入*/
                action:"",
                fileList: [],
                importFileVisible:false,
                fullscreenLoading:false,

                //按钮禁用
                selectDisabled:false,
                addDisabled:false,
                leadInDisabled:false,
                leadOutDisabled:false,
                enableDisabled:false,
                forbiddenDisabled:false,

                loading:false,
                isPaging:true,    //是否显示分页
                pageIndex:1,    //当前页（必传）
                pageSize :10,   //每页多少条
                currentPage:1,    //当前显示3页
                currentPage3:3,
                totalNumber: 1,     //总条数
                totalPage:1    //总页数
            };
        },
        created:function(){
            this.languageType=="zh"?this.nowLangue=this.languageScoped.zh:this.nowLangue=this.languageScoped.en;
        },
        computed:{
            languageType(){
                return this.$store.state.languageType;
            }
        },
        watch:{
            languageType(){
                this.languageType=="zh"?this.nowLangue=this.languageScoped.zh:this.nowLangue=this.languageScoped.en;
            }
        },
        //进入页面立即运行此方法
        mounted: function () {
            var _this = this;
            _this.$store.commit('currentActive', 'AautoExam');
        },
        methods:{
            //查询列表
            queryClick(){
                /*var _this=this;
                 _this.loading=true;
                 var urlAddress="";
                 if(this.isClickBySelect){
                     urlAddress="projectSubstitute/queryMaterialByPage";
                 }else{
                     urlAddress="projectSubstitute/queryIncreasementMaterialByPage";
                 }
                 var tmp={
                     productLineId:_this.formInline.productLineId,
                     legalPersonCode:_this.formInline.legalPersonCode,
                     startCreateTime:_this.formInline.startCreateTime,
                     endCreateTime:_this.formInline.endCreateTime,
                     materialCode:_this.formInline.materialCode,
                     materialName:_this.formInline.materialName,
                     status:_this.formInline.status,
                     pageIndex:_this.pageIndex,
                     pageSize:_this.pageSize
                 };
                 $.ajax({
                     type: 'POST',
                     url: _this.metadata_service+urlAddress,
                     cache: false,
                     data:JSON.stringify(tmp),
                     dataType:'JSON',
                     contentType: "application/json;charset=utf-8",
                     success: function (data) {
                         if (data.success) {
                             _this.loading=false;
                             _this.isPaging=true;
                             _this.totalPage=data.data.totalPage;
                             _this.totalNumber=data.data.totalNumber;
                             _this.productData=data.data.dataList;
                         }else{
                             _this.loading=false;
                            _this.common.errorTip(data.errorMessage)
                         }
                     }
                 });*/
            },
            // 操作启用禁用
            /*handleStatus(index, row){
                var _this=this;
                if(row.status){
                    row.status = false;
                }else{
                    row.status = true;
                }
                var tmp={id: row.id,status: row.status};
                $.ajax({
                    type: 'POST',
                    url: _this.metadata_service+"materialProperty/updateStatus",
                    cache: false,
                    data:JSON.stringify(tmp),
                    dataType:'JSON',
                    contentType: "application/json;charset=utf-8",
                    success: function (data) {
                        if (data.success) {
                            // 当前状态的显示
                            if(row.status){
                                row.statusName = _this.languageType=="zh"?' 启用':'Open';
                                var successMessage1=_this.languageType=="zh"?'启用成功！':'Open Success';
                                _this.common.successTip(successMessage1);
                            }else{
                                row.statusName = _this.languageType=="zh"?' 禁用':'Close';
                                var successMessage2=_this.languageType=="zh"?'禁用成功！':'Close Success';
                                _this.common.successTip(successMessage2);
                            }
                        }else{
                            _this.common.errorTip(data.errorMessage);
                        }
                    }
                });
            },*/
            add(){
              this.dialogAddVisible=true;
            },
            update(){
                this.dialogUpdateVisible=true;
            },
            //导入按钮
            importFile(){
                var _this=this;
                _this.importFileVisible = true;
                _this.fileList=[];
            },
            //上传文件之前的钩子
            beforeAvatarUpload(file) {
                // console.log(file);
                const isExcel2007 = file.type === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
                const isExcel2003 = file.type === 'application/vnd.ms-excel';
                if (!isExcel2007 && !isExcel2003) {
                    var errorMessage=_this.languageType=="zh"?'只能上传excel文件':'You can upload only Excel files';
                    this.$message.error(errorMessage);
                }
                return isExcel2007 || isExcel2003 ;
            },
            // 文件上传成功时的钩子
            handleAvatarSuccess(res, file) {
                var _this=this;
                if(res.success){
                    var successMessage=_this.languageType=="zh"?'上传成功！':'Upload successfully!';
                    _this.common.successTip(successMessage);
                    _this.importFileVisible = false;
                    //上传成功刷新页面
                    _this.queryEngineer();
                }else{
                    _this.fileList=[];
                    _this.common.errorTip(res.errorMessage);
                }
                // console.log(res);
                // console.log(file);
            },
            handleRemove(file, fileList) {
                console.log(file, fileList);
            },
            handlePreview(file) {
                console.log(file);
            },
            //导出
            leadingOutMask(){
                /*var _this=this;
                _this.fullscreenLoading=true;
                $.ajax({
                    type:'POST',
                    url:_this.metadata_service+'substituteGroup/Export?categoryCode='+_this.formInline.categoryCode+'&&code='+_this.formInline.code+'&&materialCode='+_this.formInline.materialCode+'&&createStartTime='+_this.formInline.createStartTime+'&&createEndTime='+_this.formInline.createEndTime,
                    cache:false,
                    contentType:"application/json;charset=utf-8",
                    success:function(data){
                        _this.fullscreenLoading=false;
                        window.location.href=_this.metadata_service+'substituteGroup/Export?categoryCode='+_this.formInline.categoryCode+'&&code='+_this.formInline.code+'&&materialCode='+_this.formInline.materialCode+'&&createStartTime='+_this.formInline.createStartTime+'&&createEndTime='+_this.formInline.createEndTime;
                        var successMessage=_this.languageType=="zh"?'导出成功':'Export successful';
                        _this.common.successTip(successMessage);
                    },
                    error:function(){
                        _this.fullscreenLoading=false;
                        var errorMessage=_this.languageType=="zh"?'导出失败':'Export failure';
                        _this.common.errorTip(errorMessage);
                    }
                })*/
            },
        }
    }
</script>



